package com.example.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/admin")
public class AdminController {

    @GetMapping("/dashboard")
    public String adminDashboard(Model model, HttpSession session) {
        // 检查登录状态和用户类型
        if (session.getAttribute("loggedIn") == null || !"admin".equals(session.getAttribute("userType"))) {
            return "redirect:/index";
        }

        model.addAttribute("username", session.getAttribute("username"));
        model.addAttribute("userType", session.getAttribute("userType"));
        return "admin"; // 返回管理员视图
    }
}